package jmine.tec.sync.channel;

import java.io.IOException;
import java.net.Socket;

import jmine.tec.sync.DataPushChannel;

/**
 * {@link DataPushChannel} que empurra os dados via um {@link Socket} normal. Para cada vez que o metodo
 * {@link #pushCommandsAsBytes(byte[])} eh chamado, um novo {@link Socket} eh aberto
 * 
 * @author takeshi
 */
public class SocketDataPushChannel extends AbstractDataPushChannel implements DataPushChannel {

    private int port;

    private String host = "localhost";

    /**
     * {@inheritDoc}
     */
    public void pushCommandsAsBytes(byte[] data) throws IOException {
        Socket socket = new Socket(this.getHost(), this.port);
        try {
            socket.getOutputStream().write(data);
        } finally {
            socket.close();
        }
    }

    /**
     * @return the port
     */
    public int getPort() {
        return this.port;
    }

    /**
     * @param port the port to set
     */
    public void setPort(int port) {
        this.port = port;
    }

    /**
     * @return the host
     */
    public String getHost() {
        return this.host;
    }

    /**
     * @param host the host to set
     */
    public void setHost(String host) {
        this.host = host;
    }

}
